﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;
using System.Reflection;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
namespace Viewer.BusinessObject.BusinessEntities
{
    [Serializable()]
    public partial class QUNhomNguoiDung_NguoiDung : BusinessBase
    {
        CommonCode common = new CommonCode();
        DataClassesDataContext db = new DataClassesDataContext();
        public void Save()
        { }

        public void DeleteAllWithNguoiDungID(int pNguoiDungID)
        {
            var query = (from a in db.QUNhomNguoiDung_NguoiDungs
                         where a.NguoiDungID.Equals(pNguoiDungID)
                         select a).ToList();
            if (query.Count > 0)
            {
                db.QUNhomNguoiDung_NguoiDungs.DeleteAllOnSubmit(query);
                db.SubmitChanges();
            }
        }
        public string TenLoaiNhomNguoiDung { get; set; }
        public List<QUNguoiDung> GetNguoiDungByNhomNguoiDungID(int pNhomNguoiDungID)
        {
            return (from m in this.Context.QUNhomNguoiDung_NguoiDungs
                    where m.NhomNguoiDungID == pNhomNguoiDungID
                    select m.QUNguoiDung).ToList();

        }

        public List<QUNhomNguoiDung> GetNhomNguoiDungByNguoiDungID(int pNguoiDungID)
        {
            List<QUNhomNguoiDung> lstResult = new List<QUNhomNguoiDung>();

            lstResult = (from m in this.Context.QUNhomNguoiDung_NguoiDungs
                         where m.NguoiDungID == pNguoiDungID
                         select m.QUNhomNguoiDung).ToList();
            //foreach (QUNhomNguoiDung item in lstResult)
            //{
            //    item.TenLoaiNhomNguoiDung = common.LoadCommonCodeById(item.LoaiNhomNguoiDungID);
            //}
            return lstResult;
        }
        public void SaveDataList(int nhanVienId, List<QUNhomNguoiDung_NguoiDung> lstData)
        {
            var query = (from a in this.Context.QUNhomNguoiDung_NguoiDungs
                         where a.NguoiDungID.Equals(nhanVienId)
                         select a).ToList();
            if (query.Count > 0)
            {
                this.Context.QUNhomNguoiDung_NguoiDungs.DeleteAllOnSubmit(query);
                this.Context.SubmitChanges();
            }
            if (lstData.Count > 0)
            {
                foreach (QUNhomNguoiDung_NguoiDung item in lstData)
                {
                    QUNhomNguoiDung_NguoiDung newItem = new QUNhomNguoiDung_NguoiDung();
                    newItem.NguoiDungID = item.NguoiDungID;
                    newItem.NhomNguoiDungID = item.NhomNguoiDungID;
                    this.Context.QUNhomNguoiDung_NguoiDungs.InsertOnSubmit(newItem);
                }
            }
            this.Context.SubmitChanges();
        }

    }
}